#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
int n,m,L,V;
int d[N],v[N],a[N];
int p[N];
int b[N];
int f[N];
int flag;
int sum,ans;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T;cin >> T;
    while(T--){
        memset(b,0,sizeof b);
        memset(f,0,sizeof f);
        flag = 0;
        cin >> n >> m >> L >> V;
        for(int i = 1;i <= n;i++){
            cin >> d[i] >> v[i] >> a[i];
            if(a[i] != 0) flag = 1;
        }
        for(int i = 1;i <= m;i++) cin >> p[i];
        sum = 0;ans = 0;
        sort(p+1,p+m+1);
        if(!flag){
            for(int i = 1;i <= n;i++){
                if(v[i] > V && d[i] <= p[m]) sum++;
            }
            if(sum != 0) ans = 1;
            cout << sum << ' ' << m-ans << "\n";
            continue;
        }
        for(int i = 1;i <= m;i++){
            for(int j = 1;j <= n;j++){
                if(p[i] > d[j]) continue;
                double ds = (p[i]-d[j]);
                double nv = sqrt(v[j]*v[j]+2.*a[j]*ds);
                if(nv <= 0) continue;
                if(abs(nv-V) >= 1e-5){
                    if(f[j] != 1) ans++;
                    f[j] = 1;
                    b[i]++;
                }
            }
        }
        cout << ans << ' ';
        sort(b+1,b+m+1);
        int q = n;
        for(int i = m;i >= 1;i--){
            q -= b[i];
            sum ++;
            if(q <= 0) break;
        }
        cout << m-sum << "\n";
    }
    return 0;
}
